package com.zzyl.serve.controller.member;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.dto.UserAddRequestDto;
import com.zzyl.serve.dto.UserLoginRequestDto;
import com.zzyl.serve.vo.DeviceDataGraphVo;
import com.zzyl.serve.vo.ElderPageVo;
import com.zzyl.serve.vo.HealthDataVo;
import com.zzyl.serve.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.FamilyMember;
import com.zzyl.serve.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author itheima
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;




    /**
     * 小程序端 用户登录
     */
	@PostMapping("/login")
    @ApiOperation("小程序端 用户登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto dto) {

        LoginVo vo = familyMemberService.login(dto);


        return R.ok(vo);
    }

    //h
    /**
     * 小程序端 绑定老人
     */
    @PostMapping("/add")
    @ApiOperation("小程序端 绑定老人")
    public AjaxResult BindingFamilyMember(@RequestBody UserAddRequestDto dto) {

        familyMemberService.BindingFamilyMember(dto);

        return AjaxResult.success();
    }
    /**
     * 小程序端 查询家人列表
     */
    @GetMapping ("/my")
    @ApiOperation("小程序端 查询家人列表")
    public AjaxResult myFamilyMember() {
        List<Map<String, Object>> list = familyMemberService.myFamilyMember();
        return AjaxResult.success(list);
    }
    /**
     * 小程序端 查询家人列表（分页查询）
     */
    @GetMapping ("/list-by-page")
    @ApiOperation("小程序端 查询家人列表（分页查询）")
    public AjaxResult PageFamilyMember() {
        startPage();
        List<ElderPageVo> list = familyMemberService.PageFamilyMember();
        return AjaxResult.success(list);
    }
    /**
     * 小程序端 解绑家人
     */
    @DeleteMapping ("/deleteById")
    @ApiOperation("小程序端 解绑家人")
    public AjaxResult deleteByIdFamilyMember( Integer id) {
        familyMemberService.deleteByIdFamilyMember(id);
        return AjaxResult.success();
    }



    // y
    /**
     * 查询健康数据
     * 接口地址:/member/user/queryServiceProperties/{iotId}
     * 请求方式:GET
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryDeviceDataListByDay(@PathVariable String iotId) {
        List<HealthDataVo> list = familyMemberService.queryServiceProperties(iotId);
        return AjaxResult.success(list);
    }


    /**
     * 按天统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByDay
     * 请求方式:GET
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(String functionId,
                                                         Long startTime,
                                                         Long endTime,
                                                         String iotId) {
        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByDay(functionId,
                startTime, endTime, iotId);
        AjaxResult ajax = AjaxResult.success(list);
        ajax.put("operationTime", null);
        return ajax;
    }


    /**
     * 按周统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByWeek
     * 请求方式:GET
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(String functionId,
                                                Long startTime,
                                                Long endTime,
                                                String iotId) {
        List<DeviceDataGraphVo> list = familyMemberService.queryDeviceDataListByWeek(functionId,
                startTime, endTime, iotId);
        AjaxResult ajax = AjaxResult.success(list);
        ajax.put("operationTime", null);
        return ajax;
    }














}
